/**
 * 
 */
package com.sst.social.networking.database;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sst.social.networking.R;

/**
 * @author Rakesh
 * 
 */
public class CustomCursorAdapter extends CursorAdapter {

	SQLiteDatabase dh = DatabaseHelper.getInstance().getDb();
	private LayoutInflater mInflater;
	private Context mContext;
	Cursor cursor;

	public CustomCursorAdapter(Context context, Cursor c) {
		super(context, c);
		// TODO Auto-generated constructor stub
		mInflater = LayoutInflater.from(context);
		mContext = context;
		cursor = c;
	}

	@Override
	public void bindView(View view, Context context, final Cursor cursor) {
		// TODO Auto-generated method stub
		ViewHolder holder = (ViewHolder) view.getTag();

		holder.setTvTitle((TextView) view
				.findViewById(R.id.gridviewimage_title));
		holder.setImType((ImageView) view
				.findViewById(R.id.gridviewimage_image));

		holder.getTvTitle().setText(
				cursor.getString(cursor.getColumnIndex("title")));
		holder.getImType().setBackgroundResource(R.drawable.icon);

		int _id = cursor.getInt(cursor.getColumnIndex("_id"));
		String type = cursor.getString(cursor.getColumnIndex("title"));
		if (type.equals("Facebook")) {
			holder.getImType().setBackgroundResource(R.drawable.icon);
		} else if (type.equals("Orkut")) {
			holder.getImType().setBackgroundResource(R.drawable.icon);
		} else if (type.equals("Twiter")) {
			holder.getImType().setBackgroundResource(R.drawable.icon);
		}
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		View convertView = mInflater.inflate(R.id.SocialNetworkingImageGrid,
				parent, false);
		holder = new ViewHolder(convertView);
		convertView.setTag(holder);
		return convertView;
	}

}
